#include <stdio.h>

/*
 * 全局变量
 */

int sum, product;

void f1(int x, int y, int * sum, int * product)
{
	*sum = x + y;
	*product = x * y;
}

void main()
{
	f1(123, 456, &sum, &product);
	printf("sum=%d, product=%d\n", sum, product);	// sum=579, product=56088
}

#if 0
/*
 * intel
 */
0000000000001149 <f1>:
    1149:	f3 0f 1e fa          	endbr64 
    114d:	55                   	push   %rbp
    114e:	48 89 e5             	mov    %rsp,%rbp
    1151:	89 7d fc             	mov    %edi,-0x4(%rbp)
    1154:	89 75 f8             	mov    %esi,-0x8(%rbp)
    1157:	48 89 55 f0          	mov    %rdx,-0x10(%rbp)		// sum
    115b:	48 89 4d e8          	mov    %rcx,-0x18(%rbp)		// product
    115f:	8b 55 fc             	mov    -0x4(%rbp),%edx
    1162:	8b 45 f8             	mov    -0x8(%rbp),%eax
    1165:	01 c2                	add    %eax,%edx
    1167:	48 8b 45 f0          	mov    -0x10(%rbp),%rax		// rax=sum address
    116b:	89 10                	mov    %edx,(%rax)		// *sum=edx
    116d:	8b 45 fc             	mov    -0x4(%rbp),%eax
    1170:	0f af 45 f8          	imul   -0x8(%rbp),%eax		// x * y
    1174:	89 c2                	mov    %eax,%edx		// edx=x*y
    1176:	48 8b 45 e8          	mov    -0x18(%rbp),%rax		// rax=product address
    117a:	89 10                	mov    %edx,(%rax)		// *product=x*y
    117c:	90                   	nop
    117d:	5d                   	pop    %rbp
    117e:	c3                   	retq   

000000000000117f <main>:
    117f:	f3 0f 1e fa          	endbr64 
    1183:	55                   	push   %rbp
    1184:	48 89 e5             	mov    %rsp,%rbp
    1187:	48 8d 0d 8a 2e 00 00 	lea    0x2e8a(%rip),%rcx        # 4018 <product>	address
    118e:	48 8d 15 7f 2e 00 00 	lea    0x2e7f(%rip),%rdx        # 4014 <sum>		address
    1195:	be c8 01 00 00       	mov    $0x1c8,%esi
    119a:	bf 7b 00 00 00       	mov    $0x7b,%edi
    119f:	e8 a5 ff ff ff       	callq  1149 <f1>
    11a4:	8b 15 6e 2e 00 00    	mov    0x2e6e(%rip),%edx        # 4018 <product>
    11aa:	8b 05 64 2e 00 00    	mov    0x2e64(%rip),%eax        # 4014 <sum>
    11b0:	89 c6                	mov    %eax,%esi
    11b2:	48 8d 3d 4b 0e 00 00 	lea    0xe4b(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    11b9:	b8 00 00 00 00       	mov    $0x0,%eax
    11be:	e8 8d fe ff ff       	callq  1050 <printf@plt>
    11c3:	90                   	nop
    11c4:	5d                   	pop    %rbp
    11c5:	c3                   	retq   
    11c6:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    11cd:	00 00 00 

/*
 * arm
 */
000000000040055c <f1>:
  40055c:	d10083ff 	sub	sp, sp, #0x20
  400560:	b9001fe0 	str	w0, [sp, #28]
  400564:	b9001be1 	str	w1, [sp, #24]
  400568:	f9000be2 	str	x2, [sp, #16]
  40056c:	f90007e3 	str	x3, [sp, #8]
  400570:	b9401fe1 	ldr	w1, [sp, #28]
  400574:	b9401be0 	ldr	w0, [sp, #24]
  400578:	0b000021 	add	w1, w1, w0
  40057c:	f9400be0 	ldr	x0, [sp, #16]
  400580:	b9000001 	str	w1, [x0]
  400584:	b9401fe1 	ldr	w1, [sp, #28]
  400588:	b9401be0 	ldr	w0, [sp, #24]
  40058c:	1b007c21 	mul	w1, w1, w0
  400590:	f94007e0 	ldr	x0, [sp, #8]
  400594:	b9000001 	str	w1, [x0]
  400598:	d503201f 	nop
  40059c:	910083ff 	add	sp, sp, #0x20
  4005a0:	d65f03c0 	ret

00000000004005a4 <main>:
  4005a4:	a9bf7bfd 	stp	x29, x30, [sp, #-16]!
  4005a8:	910003fd 	mov	x29, sp
  4005ac:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  4005b0:	9100e001 	add	x1, x0, #0x38
  4005b4:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  4005b8:	9100d000 	add	x0, x0, #0x34
  4005bc:	aa0103e3 	mov	x3, x1
  4005c0:	aa0003e2 	mov	x2, x0
  4005c4:	52803901 	mov	w1, #0x1c8                 	// #456
  4005c8:	52800f60 	mov	w0, #0x7b                  	// #123
  4005cc:	97ffffe4 	bl	40055c <f1>
  4005d0:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  4005d4:	9100d000 	add	x0, x0, #0x34
  4005d8:	b9400001 	ldr	w1, [x0]
  4005dc:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  4005e0:	9100e000 	add	x0, x0, #0x38
  4005e4:	b9400002 	ldr	w2, [x0]
  4005e8:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005ec:	911ac000 	add	x0, x0, #0x6b0
  4005f0:	97ffff98 	bl	400450 <printf@plt>
  4005f4:	d503201f 	nop
  4005f8:	a8c17bfd 	ldp	x29, x30, [sp], #16
  4005fc:	d65f03c0 	ret


#endif

